﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mail;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;


namespace search
{
	/// <summary>
	/// ApproveArticle 的摘要说明。
	/// </summary>
	public partial class ApproveArticle : System.Web.UI.Page
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(Request["id"] == null)
				return;

			this.Literal1.Text = "<iframe id=iframe1 scrolling=auto src='Article.aspx?id=" + Request["id"].ToString() + "' align=absmiddle width='100%' height='100%' frameBorder=0></iframe>";

			if(!Page.IsPostBack)
			{
				DataSet ds = SearchDataAccess.GetDataSet("SELECT * FROM ForumCategories WHERE ForumID=11");
                                
				DropDownList1.DataSource = ds.Tables[0].DefaultView;
				DropDownList1.DataTextField = "CategoryName";
				DropDownList1.DataValueField = "CategoryID";
				DropDownList1.SelectedValue = "44";

				DropDownList1.DataBind();
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion


        protected void Button1_Click1(object sender, EventArgs e)
        {
			//先填写审批意见和修改文章的状态，然后以审批人的邮箱发一封邮件给发帖人
			DataSet ds = SearchDataAccess.GetUser(Request.Cookies["Email"].Value);
			long approveuserid = Convert.ToInt64(ds.Tables[0].Rows[0]["UserID"]);
			SearchDataAccess.ApproveArticle(Convert.ToInt64(Request["id"]), this.TextBox1.Text, approveuserid, 
						this.DropDownList2.SelectedValue, Convert.ToInt64(this.DropDownList1.SelectedValue));

//			if(this.CheckBox1.Checked)
//			{
//				ds = SearchDataAccess.GetArticleByPostID(Convert.ToInt64(Request["id"]));
//				DataRow dr = ds.Tables[0].Rows[0];
//
//				MailMessage MyMail = new MailMessage();
//				MyMail.From = "zxh@szkaifa.com";
//				MyMail.To = dr["Email"].ToString();
//				MyMail.Subject = "泉源发帖审核——" + dr["Subject"].ToString();
//				MyMail.Body = dr["NickName"].ToString() + "，你好！\n 你于" + Convert.ToDateTime(dr["CreateDate"]).ToString() + "发布的文章已通过审核。";
//
//				MyMail.BodyEncoding = System.Text.Encoding.UTF8;
//				SmtpMail.SmtpServer = "mail.szkaifa.com";
//				SmtpMail.Send(MyMail);
//
//
//			}
//
			Response.Write("<script defer>alert('审批完成'); close();try{opener.focus();opener.document.all('Form1').submit();}catch(e){}</script>");
		}

       
	}
}
